package com.smcaiot.filesync.starter.app;

import cn.hutool.core.util.StrUtil;
import com.smcaiot.filesync.starter.annotation.ApiPrefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: cz
 * @Date: 2023/6/29
 * @Description:
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private FileSyncProperties fileSyncProp;

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        String apiPrefix = StrUtil.isBlank(fileSyncProp.getApiPrefix()) ? "" : fileSyncProp.getApiPrefix();
        configurer.addPathPrefix(apiPrefix, c -> c.isAnnotationPresent(ApiPrefix.class));
    }

}
